package cn.zhouchao.basic.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * ApplicationContextAware extends Aware
 * 方法就一个 void setApplicationContext(ApplicationContext var1) throws BeansException;
 */
@Component
public class SpringUtil implements ApplicationContextAware {
    // 静态的私有化 ApplicationContext 象
    private static ApplicationContext appContext;

    public static ApplicationContext getContext() {
        return appContext;
    }

    /**
     * 重写 ApplicationContextAware
     * 其中仅一个方法，再将其方法参数对象赋给 ApplicationContext 的对象
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        appContext = applicationContext;
    }

    // 创建一个方法，作为一个 ApplicationContext 的返回
    public static ApplicationContext getappContext() {
        return appContext;
    }

}
